var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
define(["require", "exports", "maishu-chitu-service", "maishu-chitu-admin/static", "js-md5"], function (require, exports, maishu_chitu_service_1, static_1, md5) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class LocalService extends static_1.Service {
        constructor() {
            super(...arguments);
            this.loginInfo = new maishu_chitu_service_1.LocalValueStore("login-info");
        }
        ajax(url, options) {
            options.headers = options.headers || {};
            if (this.loginInfo.value)
                options.headers["token"] = this.loginInfo.value.token;
            return super.ajax(url, options);
        }
        login(username, password) {
            return __awaiter(this, void 0, void 0, function* () {
                password = md5(password);
                let url = this.localUrl("login");
                let r = yield this.postByJson(url, { username, password });
                this.loginInfo.value = r;
                return r;
            });
        }
    }
    exports.LocalService = LocalService;
});
